home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5611 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Converting integer to char/string?
  5. Date: 5 Feb 1996 21:24:56 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4f5sj8$5f8@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: 38.8.60.2
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 05, 1996 17:25:03 in article <Converting integer to char/string?>,
  15. 'Gilbert Banks <gilbertb@bnr.ca>' wrote: 
  16.  
  17.  
  18. >What is the function and header for converting an integer to char or
  19. string? 
  20. >I think the header is <stdlib.h>. 
  21.  
  22. Nope, not stdlib.h.   
  23.  
  24. First, integer to char: 
  25.    int i = somenum(); 
  26.    char c = i; 
  27.  
  28. Second, integer to string: 
  29.  
  30.         C                            C++ 
  31.   ------------------         --------------------- 
  32.   #include <stdio.h>         #include <ostrstream.h> 
  33.   char s[25];                 ostrstream os; 
  34.   int n = somenum();          int n = somenum(); 
  35.   sprintf("%d", n);           os << n << ends; 
  36.  
  37. If you are on a DOS or other Inel machine, change the C++ 
  38. version to read #include <ostrstrea.h> 
  39.  
  40. -- 
  41. Pete Grant 
  42. Kalevi, Inc. 
  43. Object Oriented Software Development
  44.